Home:ALL Converter>How to retrieve top three documents based on inner array from MongoDB

How to retrieve top three documents based on inner array from MongoDB

Ask Time:2018-06-21T04:24:16         Author:Vuyyururajashekar Reddy

Json Formatter

How can I retrieve the top three docs based on like array size as shown in the below response from MongoDB? I am using Node.js.

 "status": true,
        "data": [
            {
                "tags": [
                    "IoT"
                ],
                "fileUrls": [
                    "www.miraclesoft1.com",
                    "www.miraclesoft2.com"
                ],
                "createdDate": "2018-06-18T14:45:17.651Z",
                "_id": "5b27e57116e7821bd0b2a0f3",
                "title": "Ide hub testing7",
                "description": "Meet Aditi - The Co-ordinator Bot with Amazon Alexa and AWS Lambda Meet Aditi - The Co-ordinator Bot with Amazon Alexa and AWS Lambda",
                "category": "Development",
                "ideaStatus": "false",
                "createdByLoginId": "rkanumetta",
                "createdByName": "Rajesh Kumar Kanumetta",
                "like": [],
                "comments": [],
                "__v": 0
            },
            {
                "tags": [
                    "IoT"
                ],
                "fileUrls": [
                    "www.miraclesoft1.com",
                    "www.miraclesoft2.com"
                ],
                "createdDate": "2018-06-18T14:45:17.651Z",
                "_id": "5b27e57516e7821bd0b2a0f4",
                "title": "Ide hub testing8",
                "description": "Meet Aditi - The Co-ordinator Bot with Amazon Alexa and AWS Lambda Meet Aditi - The Co-ordinator Bot with Amazon Alexa and AWS Lambda",
                "category": "Development",
                "ideaStatus": "false",
                "createdByLoginId": "rkanumetta",
                "createdByName": "Rajesh Kumar Kanumetta",
                "like": [],
                "comments": [],
                "__v": 0
            }

Author:Vuyyururajashekar Reddy,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50956488/how-to-retrieve-top-three-documents-based-on-inner-array-from-mongodb
yy